/* D:TalkTalk/piecesofuk version */
/**
 * @author Chris Groves
 *
 **/

/*
 to compress...
 d:
 cd TalkTalk\piecesofuk\Javascript
 java -jar D:\Programming\Javascript\yuicompressor-2.3.5\build\yuicompressor-2.3.5.jar POUKindex.js -o POUKindex.min.js
*/

/* todo...
  DONE: Put all output into their own Dialogs, create a dialog manager to hide/show dialogs from a menu
  DONE: update latest "calendar" for the new calendar code
  DONE: rewrite calendar code (in testPage.html) include more data in the view
  DONE: add volume control
  DONE: Fix width problem on latest window
  DONE: If a feed fails to load then click on relevant item in latest will force a reload
  DONE:but not tested on an @tweet - Change twitter feed: pass all #Jewel, then reject anything containing @xxxx
  DONE: amend calendar etc to use global dates
  DONE: make the today global
  DONE: latest: calendar: also show this week's events; change order, make calendar last
  enhance ajax/json error checking
  DONE: Incorporate song database
  youTube quiz?
*/
/* bugs...
  FIXED: IE7 object error loading home
  Duplicate data when reloading calendar?
  FIXED: Chrome/IE7/Opera body scroll bar appearing (Fixed for Opera and Chrome)
  FIXED: FF: loaded/played don't get reset when selecting another video
  IE8 "Error: 'null' is null or not an object"
  IE7/8 sometimes get Error: 'PIECESOFUK.verses.length' is null or not an object; also very slow!!!!
  IE8: ytplayer skip points/loaded appear at the top of the window; lyrics not appearing
  IE7: lyrics not appearing
  FIXED:IE7/8 Invalid argument, possibly in the new calendar code
  FIXED:Firefox: the youtube video stops playing when the tabs change
  FIXED:Opera: infoView TOP position is incorrect - this is a known jquery/opera bug
  FIXED:Opera: skip point icons not showing
  IE7: youtube video audio doesn't stop when the infoview is closed
  IE7: lyrics not centred; translated lyrics don't appear
  IE8  Error: Object required when selecting language
  FIXED?Chrome: Dialog opens with title bar at the bottom
  FIXED: N800: tabs not working, video not playing
  FIXED:'Latest' links don't work in suspend mode
  FIXED:Singles text isn't translated. Need to rewrite the singles code. Maybe preload or translate
  when loaded.
  Sometimes the skip points are all scrunched up.
  FIXED: When clicking a single make sure the infoView is visible on screen
*/
/*
 test plan

 Load page: check latest: all feeds loaded, able to select feed and the relevant tab is shown.
 Select each tab
 Change main language. Select tabs check all relevant text is translated.
 Select youTube: make sure playlist loads; select a video; check checkpoints/lyrics/translation
 Select singles: choose YWMFM or I Do, click YT icon, does video play?
 Choose another option when a video is playing
*/

if (typeof PIECESOFUK == "undefined") {
	var PIECESOFUK = {};
}

PIECESOFUK.albumMap = {"POY" : "Pieces of You",
                       "Spirit" : "Spirit",
											 "ThisWay" : "This Way",
											 "0304" : "0304",
											 "GBAIW" : "Goodbye Alice...",
											 "PC" : "Perfectly Clear",
											 "Lullaby" : "Lullaby",
											 "Other" : "Other",
											 "unreleased" : "unreleased",
											 "not found" : "not found"};

PIECESOFUK.initIndex = function() {
	PIECESOFUK.globalInit();
	$("#latest").show()
  PIECESOFUK.latestPtr = new PIECESOFUK.latest();
	$("#about").show()
	PIECESOFUK.aboutPtr = new PIECESOFUK.about();
}

PIECESOFUK.menusInit = function() {
  $("#menu").hide();

  $("#homeMenu").click( function() {
		if ( $("#menu").is(":visible")) $("#menu").hide();
		else {
		  $(".aMenu").hide();
      $("#menu").fadeIn("fast");
		}
  });


	$("#showWindowsButton").click( function() {
		if ( $("#openWindows").is(":visible")) $("#openWindows").hide();
		else {
			$(".openWindowButton").unbind("click");
		  $("#openWindows").html("").css( "left", $("#windowControl").offset().left - 15 + "px");
		  $(".aDialog").each( function() {
			  if ( $(this).dialog("isOpen")) {
			    var $li = $("<li/>").append( $(this).prev().children().eq(0).html() ).data("item", $(this))
					     .addClass("menuItem");
			    $("#openWindows").append($li);
			  }
		  });
			$(".aMenu").hide();
			$("#openWindows").fadeIn("fast");
			$("#openWindows li").click( function() {
				$("#openWindows").hide();
				$($(this).data("item")).dialog("moveToTop");
			})
		}
	});
}

PIECESOFUK.feedsInit = function() {
  if ( PIECESOFUK.feeds == undefined ) PIECESOFUK.feeds = new Array;
	$("#twitterLink").click( function() {
		$("#menu").hide();
		$(".aView, .aControl").hide();
		$("#twitter").show();
		if (PIECESOFUK.feeds["twitter"] == undefined) PIECESOFUK.feeds["twitter"] = new PIECESOFUK.twitter();
		PIECESOFUK.feeds["twitter"].displayDialog();
		return false;
	});

	$("#POUKBlogLink").click( function() {
		$("#menu").hide();
		$(".aView, .aControl").hide();
		$("#blogger").show();
		if (PIECESOFUK.feeds["blogger"] == undefined) PIECESOFUK.feeds["blogger"] = new PIECESOFUK.blogger();
		PIECESOFUK.feeds["blogger"].displayDialog();
		return false;
	});

	$("#jewelsBlogLink").click( function() {
		$("#menu").hide();
		$(".aView, .aControl").hide();
		$("#jewelsBlog").show();
		if (PIECESOFUK.feeds["jewelsBlog"] == undefined) PIECESOFUK.feeds["jewelsBlog"] = new PIECESOFUK.jewelsBlog();
		PIECESOFUK.feeds["jewelsBlog"].displayDialog();
		return false;
	});

	$("#latestLink").click( function() {
		$("#menu").hide();
    if (PIECESOFUK.latestPtr == null) PIECESOFUK.latestPtr = new PIECESOFUK.latest();
		else {
			if ($("#latest").dialog("isOpen")) $("#latest").dialog("moveToTop");
			else $("#latest").dialog("open");
		}
		return false;
	});
	setTimeout(PIECESOFUK.controller, 1000);

}

PIECESOFUK.globalInit = function() {
	PIECESOFUK.menusInit();
	PIECESOFUK.feedsInit();
  $(".aDialog").hide();
	$("#aboutLink").click( function() {
		$("#menu").hide();
    if (PIECESOFUK.aboutPtr == null) PIECESOFUK.aboutPtr = new PIECESOFUK.about();
		else {
			if ($("#about").dialog("isOpen")) $("#about").dialog("moveToTop");
			else {
			  $("#about").dialog("open");
			  PIECESOFUK.aboutPtr.display();
			}
		}
		return false;
	});


  $("body").show();
	$(".aView, .aControl").hide();

}

try { console.log('init console... done'); } catch(e) { console = { log: function() {} } }

googleTranslateInit = function() {
}

//PIECESOFUK.bodyWidth = 0;
//PIECESOFUK.bodyHeight = 0;

/* date globals */
	PIECESOFUK.today = PIECESOFUK.now = new Date();
	PIECESOFUK.todayDD = PIECESOFUK.today.getDate();
	PIECESOFUK.todayDDx = PIECESOFUK.todayDD < 10 ? "0" + PIECESOFUK.todayDD : PIECESOFUK.todayDD;

	PIECESOFUK.todayMM = PIECESOFUK.today.getMonth() + 1; // months are offset 0
	PIECESOFUK.todayMMx = PIECESOFUK.todayMM < 10 ? "0" + PIECESOFUK.todayMM : PIECESOFUK.todayMM;

	PIECESOFUK.todayYYYY = PIECESOFUK.today.getFullYear();
	PIECESOFUK.today = new Date(PIECESOFUK.todayYYYY, PIECESOFUK.todayMM - 1, PIECESOFUK.todayDD);
	PIECESOFUK.todayVal = PIECESOFUK.today.valueOf();
	PIECESOFUK.nowVal = PIECESOFUK.now.valueOf();
	PIECESOFUK.aDay = 1000 * 24 * 60 * 60;
	PIECESOFUK.aWeek = 1000 * 24 * 60 * 60 * 7;
  PIECESOFUK.dayText = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];



/* for a dark background
PIECESOFUK.oddColour = "#232323";
PIECESOFUK.evenColour = "#353535";
*/
PIECESOFUK.oddColour = "#fcfcfc";
PIECESOFUK.evenColour = "#fefefe";

PIECESOFUK.calBgrd = {
"calendarPromo" : "#DAA520",
"calendarTV": "navy",
"calendarLive": "#B0171F",
"calendarNew": "green",
"calendarOther": "#00eeee"
}
// new calendar code

// end new calendar code
/*
PIECESOFUK.feedItem = function(name, initFn, loadFn, displayFn) {
  this.Name = name;
  this.Attempts = 0;
  this.InitFn = initFn;
  this.LoadFn = loadFn;
  this.DisplayFn = displayFn;
  this.Status = "initialising";

  this.getStatus = function() {
    return this.Status;
  }

  this.setStatus = function(newStatus) {
    this.Status = newStatus;
  }

  this.incAttemps = function() {
    ++this.Attempts;
  }
}
*/

PIECESOFUK.controlData = function() {

}
PIECESOFUK.initScreencast = function(feedsIdx) {
  PIECESOFUK.numCasts = 0;
  PIECESOFUK.atCast = 0;
  PIECESOFUK.pauseScreencast = false;
  PIECESOFUK.feeds["screencast"].setStatus("initialised");
  $("#infoView").hover( function() {
    PIECESOFUK.pauseScreencast = true;
  }, function() {
    PIECESOFUK.pauseScreencast = false;
  });
  PIECESOFUK.infoView(350, 300, "Latest...");
//  $("#infoView").attr("title", "Latest...");
//  $("#infoView").dialog({width: 350, height: 300});
//  PIECESOFUK.feeds[feedsIdx].setStatus("suspend");
}



PIECESOFUK.calendarItems = [];
PIECESOFUK.calendarItemsIdx = 0;

PIECESOFUK.calendarItem = function(date, updDate, text) {
	this.date = date;
	this.updDate = updDate;
	this.text = text; // what and where
}

PIECESOFUK.initLatest = function() {
	PIECESOFUK.globalInit();
	$("#latest").show()
	PIECESOFUK.latestPtr = new PIECESOFUK.latest();
}


PIECESOFUK.latest = function () {
  var latest = this;

  this.close = function() {
//		delete latest;
//		$("#latest").remove();
		clearTimeout(latest.calendarTimer);
//		PIECESOFUK.latestPtr = null;
  }

  $("#latest").dialog( {title: "Latest", width: 500, height: 300, close: latest.close} );
	$("#ui-dialog-title-latest")
			   .prepend('<img class="infoViewTitleImg" src="Graphics/latest.png" width="16" height="16" alt="icon">')
         .parent()
				 .css("paddingLeft", "3px");
/*
	if (PIECESOFUK.infoViewPtr == null) PIECESOFUK.infoViewPtr = new PIECESOFUK.infoView();
  PIECESOFUK.infoViewPtr.update(500, 300, "Latest news", this);
  $("#infoView").html("<div id='latest' />").css("width", "500px");
*/
//  $("#infoView").html("<div id='latest' />");


	if (PIECESOFUK.feeds["calendar"] == undefined) PIECESOFUK.feeds["calendar"] = new PIECESOFUK.calendar();
	if (PIECESOFUK.feeds["twitter"] == undefined) PIECESOFUK.feeds["twitter"] = new PIECESOFUK.twitter();
	if (PIECESOFUK.feeds["blogger"] == undefined) PIECESOFUK.feeds["blogger"] = new PIECESOFUK.blogger();
	if (PIECESOFUK.feeds["jewelsBlog"] == undefined) PIECESOFUK.feeds["jewelsBlog"] = new PIECESOFUK.jewelsBlog();


//	var latest = this;
	var calendarTimer = null;
	var twitterTimer = null;
	var jewelsBlogTimer = null;
	var bloggerTimer = null;

	var $img = $("<img>").attr("src", "Graphics/twitter.gif");
	var $entriesDiv = $("<div></div>").attr("id", "latestTwitter").addClass("latestItems");
	var $divWrap = $("<div></div>").addClass("latestItemsContainer").append($img, "Latest tweets...", $entriesDiv)
	         .attr("title", "Click to load/reload");
	$("#latest").append($divWrap);

	var $img = $("<img>").attr("src", "Graphics/blogger.gif");
	var $entriesDiv = $("<div></div>").attr("id", "latestBlogger").addClass("latestItems");
	var $divWrap = $("<div></div>").addClass("latestItemsContainer")
	      .append($img, "Latest Pieces Of UK Blog entries...", $entriesDiv).attr("title", "Click to load/reload");
	$("#latest").append($divWrap);

	var $img = $("<img>").attr("src", "Graphics/jewelIco.gif");
	var $entriesDiv = $("<div></div>").attr("id", "latestJewelsBlog").addClass("latestItems");
	var $divWrap = $("<div></div>").addClass("latestItemsContainer")
	      .append($img, "Latest Jewel Blog entries...", $entriesDiv).attr("title", "Click to load/reload");
	$("#latest").append($divWrap);

	var $img = $("<img>").attr("src", "Graphics/calendar.gif");
	var $entriesDiv = $("<div></div>").attr("id", "latestCalendar").addClass("latestItems");
	var $divWrap = $("<div></div>").addClass("latestItemsContainer")
	      .append($img, "Latest calendar entries (this week & new additions) ...", $entriesDiv).attr("title", "Click to load/reload");
	$("#latest").append($divWrap);

	this.calendar = function() {
		var found = false;
	  if (PIECESOFUK.feeds["calendar"].getStatus() == "complete") {
			$("#latestCalendar").html("").parent().attr("title", "Click to view more");
//			$("#m02y2009").next().find(".cblEntry").each( function() {
			$("#m" + PIECESOFUK.todayMMx + "y" + PIECESOFUK.todayYYYY).next().find(".cblEntry").each( function() {
				if ($(this).data("latest")) {
					found = true;
					$("#latestCalendar").append($(this).data("latest"));
				}
			})
//			$("#m02y2009").nextAll(".cblMonthHead").next().find(".cblEntry").each( function() {
			$("#m" + PIECESOFUK.todayMMx + "y" + PIECESOFUK.todayYYYY).nextAll(".cblMonthHead").next().find(".cblEntry").each( function() {
				if ($(this).data("latest")) {
					found = true;
					$("#latestCalendar").append($(this).data("latest"));
				}
			});
			$("#latestCalendar").parent().unbind("click");
			if (!found) $("#latestCalendar").append("no items found");
			$("#latestCalendar").parent().click( function() {
//				$("#main > ul").tabs('select', 4)
				document.location.href = "calendar.html";
			});

	  } else {
			$("#latestCalendar").text(PIECESOFUK.feeds["calendar"].getStatus());
			$("#latestCalendar").parent().unbind("click");
			$("#latestCalendar").parent().click( function() {
				PIECESOFUK.feeds["calendar"].setStatus("initialised");
			});
			latest.calendarTimer = setTimeout(latest.calendar, 1000);
		}

	}
/*
  this.calendar = function() {
		if (PIECESOFUK.feeds["calendar"].getStatus() == "complete") {
			$("#latestCalendar").html("").parent().attr("title", "Click to view more");
			for (var i = 0; i < PIECESOFUK.calendarItems.length; i++) {
		    var splitDate = PIECESOFUK.calendarItems[i].updDate.match(/(\d{4})[-](\d{2})[-](\d{2})[T](\d{2})[:](\d{2})[:](\d{2})/);
		    var updDate = new Date(splitDate[1], splitDate[2] - 1, splitDate[3], splitDate[4], splitDate[5], splitDate[6]);
				var flagNew = "";
			  var $div = $("<div/>").addClass("latestItem").append(PIECESOFUK.calendarItems[i].date + ": " +
													PIECESOFUK.calendarItems[i].text);
		    if ( PIECESOFUK.nowVal - updDate.valueOf() < PIECESOFUK.aWeek ) {
					$newSpan = $("<span/>").addClass("newCal").text(" new!");
					$div.append($newSpan);
				}
			  $("#latestCalendar").append($div);
			}
			$("#latestCalendar").parent().unbind("click");
			$("#latestCalendar").parent().click( function() {
				$("#main > ul").tabs('select', 4)
			});
	  } else {
			$("#latestCalendar").text(PIECESOFUK.feeds["calendar"].getStatus());
			$("#latestCalendar").parent().unbind("click");
			$("#latestCalendar").parent().click( function() {
				PIECESOFUK.feeds["calendar"].setStatus("initialised");
			});
			latest.calendarTimer = setTimeout(latest.calendar, 1000);
		}
  }
*/
	this.twitter = function() {
		if (PIECESOFUK.feeds["twitter"].getStatus() == "complete") {
			$("#latestTwitter").html("").parent().attr("title", "Click to view more");
			for (var i = 0; i < 2; i++ ) {
				var $div = $("<div/>").addClass("translatable").text( $("#twitter div").eq(i).text());
				$("#latestTwitter").append($div);
//			$("#latestTwitter").html( $("#twitter div").eq(0).text());
			}
			$("#latestTwitter").parent().unbind("click");
			$("#latestTwitter").parent().click( function() {
//				$("#main > ul").tabs('select', 1)
//		    $(".aView, .aControl").hide();
//		    $("#twitter").show();
				PIECESOFUK.feeds["twitter"].displayDialog();
			});
	  } else {
			$("#latestTwitter").text(PIECESOFUK.feeds["twitter"].getStatus());
			$("#latestTwitter").parent().unbind("click");
			$("#latestTwitter").parent().click( function() {
				PIECESOFUK.feeds["twitter"].setStatus("initialised");
			});
			latest.twitterTimer = setTimeout(latest.twitter, 1000);
			/*
			if (PIECESOFUK.feeds["twitter"].getStatus() == "suspend") {
			  $("#latestTwitter").parent().click( function() {
				  $("#main > ul").tabs('select', 1)
			  });
			}
			else latest.twitterTimer = setTimeout(latest.twitter, 1000);
			*/
		}
	}

	this.jewelsBlog = function() {
		if (PIECESOFUK.feeds["jewelsBlog"].getStatus() == "complete") {
			$("#latestJewelsBlog").html("").parent().attr("title", "Click to view more");
			for (var i = 0; i < 2; i++) {
				var $div = $("<div/>").addClass("translatable").text( $(".jewelsBlogTitle").eq(i).text());
				$("#latestJewelsBlog").append($div);
//			$("#latestJewelsBlog").html( $(".jewelsBlogTitle").eq(0).text());
			}
			$("#latestJewelsBlog").parent().unbind("click");
			$("#latestJewelsBlog").parent().click( function() {
//		    $(".aView, .aControl").hide();
//		    $("#jewelsBlog").show();
				PIECESOFUK.feeds["jewelsBlog"].displayDialog();
//				$("#main > ul").tabs('select', 3)
			});
	  } else {
			$("#latestJewelsBlog").text(PIECESOFUK.feeds["jewelsBlog"].getStatus());
			$("#latestJewelsBlog").parent().unbind("click");
			$("#latestJewelsBlog").parent().click( function() {
				PIECESOFUK.feeds["jewelsBlog"].setStatus("initialised")
			});
			latest.jewelsBlogTimer = setTimeout(latest.jewelsBlog, 1000);
			/*
		  if (PIECESOFUK.feeds["jewelsBlog"].getStatus() == "suspend") {
			  $("#latestJewelsBlog").parent().click( function() {
				  $("#main > ul").tabs('select', 3)
			  });
			}
			else latest.jewelsBlogTimer = setTimeout(latest.jewelsBlog, 1000);
			*/
		}
	}

	this.blogger = function() {
			if (PIECESOFUK.feeds["blogger"].getStatus() == "complete") {
			$("#latestBlogger").html("").parent().attr("title", "Click to view more");
			for (var i = 0; i < 2; i++) {
				var $div = $("<div/>").addClass("translatable").text( $(".blogTitle").eq(i).text());
				$("#latestBlogger").append($div);
//			$("#latestBlogger").html( $(".blogTitle").eq(0).text());
			}
			$("#latestBlogger").parent().unbind("click");
			$("#latestBlogger").parent().click( function() {
//		    $(".aView, .aControl").hide();
//		    $("#blogger").show();
				PIECESOFUK.feeds["blogger"].displayDialog();
//				$("#main > ul").tabs('select', 2)
			});
	  } else {
			$("#latestBlogger").text(PIECESOFUK.feeds["blogger"].getStatus());
			$("#latestBlogger").parent().unbind("click");
		  $("#latestBlogger").parent().click( function() {
				PIECESOFUK.feeds["blogger"].setStatus("initialised");
		  });
			latest.bloggerTimer = setTimeout(latest.blogger, 1000);
			/*
			if (PIECESOFUK.feeds["blogger"].getStatus() == "suspend") {
			  $("#latestBlogger").parent().click( function() {
				  $("#main > ul").tabs('select', 2)
			  });

			}
			else latest.bloggerTimer = setTimeout(latest.blogger, 1000);
			*/
		}
	}


	this.twitterTimer = setTimeout(latest.twitter, 1000);
	this.bloggerTimer = setTimeout(latest.blogger, 1000);
	this.jewelsBlogTimer = setTimeout(latest.jewelsBlog, 1000);
	this.calendarTimer = setTimeout(latest.calendar, 1000);

// for testing only...
/*
  $("#latest")
	.append("1dadadaaaaaadafsfsf<br>")
	.append("2dadadaaaaaadafsfsf<br>")
	.append("3dadadaaaaaadafsfsf<br>")
	.append("4dadadaaaaaadafsfsf<br>")
	.append("5dadadaaaaaadafsfsf<br>")
	.append("6dadadaaaaaadafsfsf<br>")
	.append("7dadadaaaaaadafsfsf<br>")
	.append("8dadadaaaaaadafsfsf<br>")
	.append("9dadadaaaaaadafsfsf<br>")
	.append("0dadadaaaaaadafsfsf<br>");
*/
// end for testing only


} // end PIECESOFUK.latest

PIECESOFUK.initAbout = function() {
	PIECESOFUK.globalInit();
	$("#about").show()
	PIECESOFUK.aboutPtr = new PIECESOFUK.about();
}


PIECESOFUK.about = function() {
  this.num = $(".about").length;
  this.idx = 0;
  var about = this;

  this.display = function() {
    $("#about").html($(".about").eq(about.idx).html());
    var delay = parseInt( $(".about").eq(about.idx).attr("class").match(/ (.*)/), 10);
    if (++about.idx >= about.num) about.idx = 0;
    about.timer = setTimeout(about.display, delay);
  }

  this.close = function() {
    clearTimeout(about.timer);
//		delete about;
//		$("#about").remove();
//		PIECESOFUK.aboutPtr = null;
  }
  $("#about").dialog({title: "About", width: 350, height: 200, close: about.close, position: ["right", "bottom"]});
	$("#ui-dialog-title-about")
			   .prepend('<img class="infoViewTitleImg" src="Graphics/about.png" width="16" height="16" alt="icon">')
         .parent()
				 .css("paddingLeft", "3px");

  this.timer = setTimeout(this.display, 100);
} // end PIECESOFUK.about


PIECESOFUK.infoViewPtr = null;

PIECESOFUK.infoView = function() {
  this.width = 250;
  this.height = 100;
  this.title = "Initialising...";
  this.updater = null // who is calling?

  var infoView = this;

  this.close = function(e, ui) {
    if (infoView.updater) infoView.updater.close();
  }

  $("#infoViewContainer").dialog( {width: infoView.width, height: infoView.height,
                        title: infoView.title, close: infoView.close});

  this.update = function(width, height, title, updater) {
    if ( !$("#infoViewContainer").dialog("isOpen") ) { $("#infoViewContainer").dialog("open")}
    $("#infoView").children().remove();
    if (infoView.updater) infoView.updater.close(); // close previous view
    infoView.updater = updater;

    var x = ($("body").width() - width)/2;
    var y = ($(window).height() - height)/2;
		if (y < 0) y = 0; // fix opera bug
    $("#infoViewContainer").prev().find("#ui-dialog-title-infoViewContainer").text(title);
// updated for ui 1.6    $("#infoViewContainer").parent().parent().animate({width: width, height: height, left: x, top: y });
    $("#infoViewContainer").parent().animate({width: width, height: height, left: x, top: y });
    $("#infoViewContainer").css({height: height-29, width: width});
  }
}


PIECESOFUK.feed = function() { // common feed data/functions
//  this.status = "initialised";
  this.status = "initialising";

  this.setStatus = function(newStatus) {
    $("#"+this.name+"Status").text(newStatus);
    this.status = newStatus;
  }

  this.getStatus = function() {
    return this.status;
  }

  this.suspend = function() {
    $("#"+this.name+"Status").text("suspended");
    this.setStatus("suspended");
  }
}

PIECESOFUK.initJewelsBlog = function() {
	PIECESOFUK.globalInit();
	$("#jewelsBlog").show()
  PIECESOFUK.feeds["jewelsBlog"] = new PIECESOFUK.jewelsBlog();
	PIECESOFUK.feeds["jewelsBlog"].displayDialog();
//  PIECESOFUK.feeds["jewelsBlog"].suspend();
}

PIECESOFUK.jewelsBlog = function() {
  this.items = [];
  this.index = -1;
  this.name = "jewelsBlog";

  this.item = function(title, date, url, type, text) {
    this.Title = title;
    this.Date = date;
    this.Url = url;
    this.Type = type;
    this.Text = text;
  }

  var jewelsBlog = this;

	this.initialise = function() {
		jewelsBlog.setStatus("initialised");
	}

  this.displayDialog = function() {
		if ( $("#jewelsBlog").hasClass("ui-dialog-content") ) {
			if ($("#jewelsBlog").dialog("isOpen")) $("#jewelsBlog").dialog("moveToTop");
			else $("#jewelsBlog").dialog("open");
		}
		else {
			$("#jewelsBlog").dialog( {title: "Jewel's Blog", width: 450, height: 400, close: jewelsBlog.close});
	    $("#ui-dialog-title-jewelsBlog")
			   .prepend('<img class="infoViewTitleImg" src="Graphics/jewelIco.gif" width="16" height="16" alt="icon">')
         .parent()
				 .css("paddingLeft", "3px");
		}
	}

	this.close = function() {

	}

  this.load = function() {
    jewelsBlog.setStatus("loading");
    $.getJSON("http://pipes.yahoo.com/pipes/pipe.run?_id=mGIJe3c53RG_l_r16UjTQA&_render=json&_callback=?", this.read);
  }

  this.read = function(json) {
    if (json.value == undefined) {
      jewelsBlog.setStatus("failed");
      return;
    }
    for (var i = 0; i < json.value.items.length; i++) {
      ++jewelsBlog.index;
      var theDate = new Date(json.value.items[i].date);
      jewelsBlog.items[jewelsBlog.index]= new jewelsBlog.item(
        json.value.items[i].title, theDate, json.value.items[i].link,
         "Blog", json.value.items[i].content);
    }
    jewelsBlog.setStatus("loaded");
  }

  this.display = function() {
    jewelsBlog.items.sort(PIECESOFUK.sortDates);
    var bCount = 0;
    $("#jewelsBlog").html("");
    for (var i = 0; i < jewelsBlog.items.length; i++) {
      var a = $("<a></a>").attr("href", jewelsBlog.items[i].Url).
                         html(jewelsBlog.items[i].Title).addClass("jewelsBlogTitle");
      var dSpan = $("<span></span>").addClass("jewelsBlogDate").text(jewelsBlog.items[i].Date.toString().slice(0,15));
      var content = $("<div></div>").addClass("jewelsBlogContent").text(jewelsBlog.items[i].Text.replace(/<\/?[^>]+>/gi, '').replace(/&nbsp;/gi, ''));

      $("<div></div>").addClass("jewelsBlogEntry translatable").append(a).append(dSpan).append(content)
             .css("backgroundColor", (++bCount%2)? PIECESOFUK.oddColour : PIECESOFUK.evenColour)
                     .appendTo("#jewelsBlog");
    }
    $(".jewelsBlogEntry").hover( function(e) {
      $(".jewelsBlogContent").hide();
      $(".jewelsBlogContent", this).show();
    }, function() {});
		$("#jewelsBlog a").attr("target", "_blank");
    jewelsBlog.setStatus("complete");
  }
} // end jewelsBlog

PIECESOFUK.jewelsBlog.prototype = new PIECESOFUK.feed();

PIECESOFUK.initPOUKBlog = function() {
	PIECESOFUK.globalInit();
	$("#blogger").show()
  PIECESOFUK.feeds["blogger"] = new PIECESOFUK.blogger();
	PIECESOFUK.feeds["blogger"].displayDialog();
//  PIECESOFUK.feeds["blogger"].suspend();

}


PIECESOFUK.blogger = function() {
  this.name = "blogger";
  this.newsData = [];

  var blogger = this;

	this.initialise = function() {
		blogger.setStatus("initialised");
	}

  this.displayDialog = function() {
		if ( $("#blogger").hasClass("ui-dialog-content") ) {
			if ($("#blogger").dialog("isOpen")) $("#blogger").dialog("moveToTop");
			else $("#blogger").dialog("open");
		}
		else {
			$("#blogger").dialog( {title: "Pieces Of UK blog", width: 600, height: 400, close: blogger.close});
	    $("#ui-dialog-title-blogger")
			   .prepend('<img class="infoViewTitleImg" src="Graphics/blogger.gif" width="16" height="16" alt="icon">')
         .parent()
				 .css("paddingLeft", "3px");
		}
	}


	this.close = function() {

	}

  this.load = function() {
    blogger.setStatus("loading");
    var theURL = "http://piecesofuk.blogspot.com/feeds/posts/default?alt=json-in-script&max-results=15&callback=?"
    $.getJSON(theURL, this.read);
  }

  this.read = function(json) {
	  if (json.feed.entry == undefined) {
      blogger.setStatus("failed");
      return false;
    }
	  blogger.newsData = json.feed;
    blogger.setStatus("loaded");
    return true;
  }

  this.display = function() {
    var newsData = blogger.newsData;
    var outerDiv = $("<div></div>");
    var bCount = 0;
    for (var i = 0; i < newsData.entry.length; i++) {
      var entry = newsData.entry[i];
	    if (PIECESOFUK.checkJewel(entry)) {
		    var bloggerDiv = $("<div></div>");
        var $blogDate = $("<b></b>").addClass("blogDate")
                                            .text(PIECESOFUK.formatDate(entry.published.$t) + " ");
        bloggerDiv.append($blogDate).addClass("bloggerDiv translatable");
		     var alturl;
    	  for (var k = 0; k < entry.link.length; k++) {
      	  if (entry.link[k].rel == 'alternate') {
        	  alturl = entry.link[k].href;
        	  break;
      	  }
    	  }
//		  var $a = $("<a></a>").addClass("blogLink").attr({href: alturl, target: "_blank"})
//                                                 .text(entry.title.$t).appendTo(bloggerDiv);
        $("<span></span>").addClass("blogTitle").
          text(entry.title.$t+" ").attr("title","click to view more").appendTo(bloggerDiv);
		    $("<a></a>").addClass("blogLink").attr({href: alturl})
                                                 .text("(view original)").appendTo(bloggerDiv);
		    var summarySpan = $("<div></div>");
		    summarySpan.addClass("bloggerSummary");
		    bloggerTxt = entry.content.$t;
		    summarySpan.html(bloggerTxt + "<br clear='left'>").appendTo(bloggerDiv);
		    bloggerDiv.css("backgroundColor", (++bCount%2)? PIECESOFUK.oddColour : PIECESOFUK.evenColour).appendTo(outerDiv);
	    }
    }
	  $("#news").html(outerDiv);

    $(".bloggerDiv").click( function(e) {
			if ($(".bloggerSummary", this).css("display") != "none" ) {
        $(".bloggerSummary", this).slideUp();
			} else {
        $(".bloggerSummary").hide();
        $(".bloggerSummary", this).slideDown();
			}
    });
		$("#news a").attr("target", "_blank");
    blogger.setStatus("complete");
  }

} // end PIECESOFUK.blogger

PIECESOFUK.blogger.prototype = new PIECESOFUK.feed();

PIECESOFUK.initTwitter = function() {
	PIECESOFUK.globalInit();
	$("#twitter").show()
  PIECESOFUK.feeds["twitter"] = new PIECESOFUK.twitter();
	PIECESOFUK.feeds["twitter"].displayDialog();
//  PIECESOFUK.feeds["twitter"].suspend();
}

PIECESOFUK.twitter = function() {
//  this.items = [];
  this.piecesofukItems = [];
  this.jeweljkItems = [];
  this.piecesofukID = [];
  this.jeweljkID = [];
//  this.count = 0;
  this.piecesofukCount = 0;
  this.jeweljkCount = 0;
  this.piecesofukLatestDate = null;
  this.jeweljkLatestDate = null;
  this.index = 0;
  this.name = "twitter";

  var twitter = this;

	this.initialise = function() {
		twitter.setStatus("initialised");
	}

  this.displayDialog = function() {
		if ( $("#twitter").hasClass("ui-dialog-content") ) {
			if ($("#twitter").dialog("isOpen")) $("#twitter").dialog("moveToTop");
			else $("#twitter").dialog("open");
		}
		else {
//			$("#twitter").dialog( {title: "Twitter", width: 600, height: 400, close: twitter.close});

			$("#twitter").dialog( {title: "Twitter", width: $("body").width()-40, height: 400, close: twitter.close,
													 position: 'center'});
	    $("#ui-dialog-title-twitter")
			   .prepend('<img class="infoViewTitleImg" src="Graphics/twitter.gif" width="16" height="16" alt="icon">')
         .parent()
//				 .css("paddingLeft", "3px");
				 .css( {"paddingLeft" : "3px", "paddingTop" : "1px", "paddingBottom" : "1px" } );

			$("#twitterTabs").tabs();
		}
	}

  this.close = function() {

	}
/*
  this.load = function() {
    twitter.setStatus("loading");
    var theURL = "http://twitter.com/statuses/user_timeline.json?callback=?&count=15&id=piecesofuk";
//    var theURL = "http://twitter.com/statuses/user_timeline.json?callback=?&count=8&id=piecesofuk";
//  var theURL = "http://twitter.com/statuses/user_timeline/15354733.json?count=8&callback=?";
//  PIECESOFUK.addScript(theURL);
    $.getJSON(theURL, this.read);
  }

  this.read = function(json) {
    if (json == undefined) {
      twitter.setStatus("failed");
      return false;
    }
    for (var i = 0; i < json.length; i++) {
// if text contains #Jewel OR (Jewel & not @)
			if (json[i].text.indexOf("#Jewel") != -1 || (json[i].text.indexOf("Jewel") != -1 && json[i].text.indexOf("@") == -1) ) {
        var date = json[i].created_at;
        date = date.slice(0, date.indexOf(" +0000 "));
// basic regexp to replace http's with html hrefs
        text = json[i].text.replace(/(http:[^ ]*)/g, "<a href=\"$1\">$1</a>");
        twitter.items[twitter.count++] = text + " (" + date + ")";
			}
    }

    twitter.setStatus("loaded");
    return true;
  }
*/

  this.load = function() {
    twitter.setStatus("loading");
    var theURL = "http://twitter.com/statuses/user_timeline.json?callback=?&count=15&id=piecesofuk";
//    var theURL = "http://twitter.com/statuses/user_timeline.json?callback=?&count=8&id=piecesofuk";
//  var theURL = "http://twitter.com/statuses/user_timeline/15354733.json?count=8&callback=?";
//  PIECESOFUK.addScript(theURL);
    $.getJSON(theURL, this.read1);
  }

  this.read1 = function(json) {
    if (json == undefined) {
      twitter.setStatus("failed");
      return false;
    }
    for (var i = 0; i < json.length; i++) {
// if text contains #Jewel OR (Jewel & not @)
			if (json[i].text.indexOf("#Jewel") != -1 || (json[i].text.indexOf("Jewel") != -1 && json[i].text.indexOf("@") == -1) ) {
        var date = json[i].created_at;
				if (!twitter.piecesofukLatestDate) twitter.piecesofukLatestDate = date;
        date = date.slice(0, date.indexOf(" +0000 "));
// basic regexp to replace http's with html hrefs
        text = json[i].text.replace(/(http:[^ ]*)/g, "<a href=\"$1\">$1</a>");
			  twitter.piecesofukID[twitter.piecesofukCount] = json[i].id;
        twitter.piecesofukItems[twitter.piecesofukCount++] = text + " (" + date + ")";
			}
    }
// now load jeweljk tweets
    var theURL = "http://twitter.com/statuses/user_timeline.json?callback=?&count=15&id=jeweljk";
    $.getJSON(theURL, twitter.read2);
		return true;
  }

  this.read2 = function(json) {
    if (json == undefined) {
      twitter.setStatus("failed");
      return false;
    }
    for (var i = 0; i < json.length; i++) {
      var date = json[i].created_at;
			if (!twitter.jeweljkLatestDate) twitter.jeweljkLatestDate = date;
      date = date.slice(0, date.indexOf(" +0000 "));
// basic regexp to replace http's with html hrefs
      text = json[i].text.replace(/(http:[^ ]*)/g, "<a href=\"$1\">$1</a>");
			twitter.jeweljkID[twitter.jeweljkCount] = json[i].id;
      twitter.jeweljkItems[twitter.jeweljkCount++] = text + " (" + date + ")";
    }
    twitter.setStatus("loaded");
		if ( new Date(twitter.jeweljkLatestDate) >= new Date(twitter.piecesofukLatestDate) ) {
			$("#twitterTabs").tabs('select', 1);
		}
    return true;

	}


/*
  this.display = function() {
    $("#twitter").html("");
		$ul = $("<ul id='twitterUL'></ul>");
    for (var i = 0; i < twitter.count; i++) {
			$li = $("<li></li>");
			$li.append(twitter.items[i]).addClass("translatable twitterEntry");
      $ul.append($li);
    }
		$("#twitter").append($ul);
    $("#twitter").append("<br />View more tweets at <a href='http://twitter.com/piecesofuk'>http://twitter.com/piecesofuk</a>");
		$("#twitter a").attr("target", "_blank");
		twitter.setStatus("complete");
  }
*/

  this.display = function() {
    $("#piecesofukTweets").html("");
		$ul = $("<ul class='twitterUL'></ul>");
    for (var i = 0; i < twitter.piecesofukCount; i++) {

			$li = $("<li></li>");
			$li.append(twitter.piecesofukItems[i]).addClass("translatable twitterEntry");

			var $orig = $("<a></a>")
				  .text(" (View Tweet)")
					.addClass("viewTweet")
					.attr("href", "http://twitter.com/piecesofuk/statuses/" + twitter.piecesofukID[i]);
			$li.append($orig)


      $ul.append($li);

    }
		$("#piecesofukTweets").append($ul);
    $("#piecesofukTweets").append("<br />View more tweets at <a href='http://twitter.com/piecesofuk'>http://twitter.com/piecesofuk</a>");
		$("#piecesofukTweets a").attr("target", "_blank");

    $("#jeweljkTweets").html("");
		$ul = $("<ul class='twitterUL'></ul>");
    for (var i = 0; i < twitter.jeweljkCount; i++) {
			$li = $("<li></li>");
			$li.append(twitter.jeweljkItems[i]).addClass("translatable twitterEntry");
			var $orig = $("<a></a>")
				  .text(" (View Tweet)")
					.addClass("viewTweet")
					.attr("href", "http://twitter.com/jeweljk/statuses/" + twitter.jeweljkID[i]);
			$li.append($orig)

      $ul.append($li);
    }
		$("#jeweljkTweets").append($ul);
    $("#jeweljkTweets").append("<br />View more tweets at <a href='http://twitter.com/jeweljk'>http://twitter.com/jeweljk</a>");
		$("#jeweljkTweets a").attr("target", "_blank");
		twitter.setStatus("complete");
  }

/*
  this.display = function() {
    $("#twitter").html("");
    for (var i = 0; i < twitter.count; i++) {
			$div = $("<div></div>");
			$div.append(twitter.items[i] + "<br />").addClass("translatable twitterEntry");
      $("#twitter").append($div);
    }
    $("#twitter").append("<br />View more tweets at <a href='http://twitter.com/piecesofuk'>http://twitter.com/piecesofuk</a>");
		$("#twitter a").attr("target", "_blank");
		twitter.setStatus("complete");
  }
*/

} // end PIECESOFUK.twitter

PIECESOFUK.twitter.prototype = new PIECESOFUK.feed();


PIECESOFUK.daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
PIECESOFUK.months = ["January", "February", "March", "April", "May", "June",
              "July", "August", "September", "October", "November", "December"];


PIECESOFUK.$preloader = $("<img>").attr("src", "Graphics/preloader002.gif").addClass("preloader");
PIECESOFUK.$cblPreloader = $("<img>").attr("src", "Graphics/cblPreloader001.gif").addClass("cblPreloader")
                  .attr("id", "cblPreloader");


PIECESOFUK.isLeapYear = function(year) {
  if (year % 400 == 0) return true;
  else if (year % 100 == 0) return false;
  else if (year % 4 == 0) return true;
  else return false;
}

/* end experimental stuff */


PIECESOFUK.initForum = function(feedsIdx) {
  PIECESOFUK.feeds[feedsIdx].setStatus("suspended");

}

PIECESOFUK.loadScreencast = function() {
  PIECESOFUK.feeds["screencast"].setStatus("loading");
  var theURL = "http://spreadsheets.google.com/feeds/list/pKZa-x-ME9yHlhJMUo1SJMg/od6/public/values?alt=json-in-script&callback=PIECESOFUK.getPiecesData"
  PIECESOFUK.addScript(theURL);
}

// store the data in a variable
/*
 var castData = [];
 $(".castData").each( function() {
  castData.push('<div class="castData">' + $(this).html() + '</div>');
 });
*/
PIECESOFUK.getPiecesData = function(json) {
  if (json.feed == undefined) {
    PIECESOFUK.feeds["screencast"].setStatus("failed");
    return false;
  }
  for (var i = 0; i < json.feed.entry.length; i++) {
    var entry = json.feed.entry[i];
	  if (entry.gsx$item.$t == "PiecesOfUK") {
		  $("#jewelCurrentText").html(entry.gsx$content.$t);
	  }
//    if (entry.gsx$item.$t == "screenCast") {
    if (entry.gsx$item.$t == "screenCastData") { /// new version !!!!!!!
      $("<div></div>").addClass("castData").html(entry.gsx$content.$t).prependTo("#ScreenCastData");
    }
  }

  if ($.browser.msie && parseInt($.browser.version, 10) < 7) {
		$("#getFireFox").removeClass("testCastData").addClass("castData");
	}

  PIECESOFUK.numCasts = $(".castData").length;
  PIECESOFUK.atCast = 0
  setTimeout(PIECESOFUK.displayScreencast, 50);
  PIECESOFUK.feeds["screencast"].setStatus("loaded");
	return true;
}

PIECESOFUK.displayScreencast = function() {
  if (!$("#screencastBody").length) return;
  if (PIECESOFUK.pauseScreencast === true || $("#videoLayer").length)  {
    setTimeout(PIECESOFUK.displayScreencast, 5000);
    return;
  }
  $("#screencastBody").fadeOut("slow", function() {
	  $("#screencastBody").html( $(".castData").eq(PIECESOFUK.atCast).html() ).slideDown("slow");
    $("#screencastBody > p").css("width", $("#screencastBody").css("width"));
    if (++PIECESOFUK.atCast === PIECESOFUK.numCasts) PIECESOFUK.atCast = 0;
  });
  setTimeout(PIECESOFUK.displayScreencast, 5000);
}

PIECESOFUK.formatDate = function(published) {
  var months = {'01': 'January','02':'February','03':'March',
      '04':'April','05':'May','06':'June','07':'July','08':'August',
	  '09':'September','10': 'October','11':'November','12':'December'};
  var daySuffix = {1: 'st', 2: 'nd', 3: 'rd', 4: 'th', 5: 'th', 6: 'th', 7: 'th', 8: 'th', 9: 'th', 10: 'th', 11: 'th', 12: 'th', 13: 'th', 14: 'th', 15: 'th', 16: 'th', 17: 'th', 18: 'th', 19: 'th', 20: 'th', 21: 'st', 22: 'nd', 23: 'rd', 24: 'th', 25: 'th', 26: 'th', 27: 'th', 28: 'th', 29: 'th', 30: 'th', 31: 'st'};
//    published is in this format: 2007-01-18T19:33:00.
  var year = published.slice(0,4);
  var month = published.slice(5,7);
  var day = parseInt(published.slice(8,10), 10);
  if (day < 10) day = "0" + day;
  return months[month].slice(0,3) + " " + day;
}

PIECESOFUK.checkJewel = function(entry) {
// we only want to read entries tagged with 'Jewel'
	if (entry.category) {
		for (i = 0; i<entry.category.length; i++) {
			if (entry.category[i].term == "Jewel") return true;
		}
	}
	return false;
}


/* Do these initialisations at the end of the HTML files
  PIECESOFUK.feeds = new Array;
  PIECESOFUK.feeds["twitter"] = new PIECESOFUK.twitter();
//  PIECESOFUK.feeds["twitter"].suspend();
  PIECESOFUK.feeds["blogger"] = new PIECESOFUK.blogger();
//  PIECESOFUK.feeds["blogger"].suspend();
  PIECESOFUK.feeds["jewelsBlog"] = new PIECESOFUK.jewelsBlog();
//  PIECESOFUK.feeds["jewelsBlog"].suspend();
  PIECESOFUK.feeds["calendar"] = new PIECESOFUK.calendar();
//  PIECESOFUK.feeds["calendar"].suspend();
*/


PIECESOFUK.controller = function() {
  for (var feedsIdx in PIECESOFUK.feeds) {
    if (PIECESOFUK.feeds[feedsIdx].getStatus() == "initialising") {
      PIECESOFUK.feeds[feedsIdx].initialise();
    } else
    if (PIECESOFUK.feeds[feedsIdx].getStatus() == "initialised") {
      PIECESOFUK.feeds[feedsIdx].load();
			break;
    } else if (PIECESOFUK.feeds[feedsIdx].getStatus() == "loaded") {
      PIECESOFUK.feeds[feedsIdx].display();
			break;
    }
  }
  setTimeout(PIECESOFUK.controller, 1000);
}


PIECESOFUK.status = {
  "calendar" : "initialising",
  "screenCast" : "initialising",
  "jewelsBlog" : "initialising",
  "news" : "initialising",
  "twitter" : "initialising",
  "forum" : "xinitialising"
}

PIECESOFUK.attempts = {
  "calendar" : 0,
  "screenCast" : 0,
  "jewelsBlog" : 0,
  "news" : 0,
  "twitter" : 0,
  "forum" : 0
}

PIECESOFUK.unableToLoadImg = new Image();
PIECESOFUK.unableToLoadImg.src = "Graphics/unableToLoadImg.png";

google.load("language", "1");
google.setOnLoadCallback(googleTranslateInit);

//PIECESOFUK.infoViewFn = null;

PIECESOFUK.youTubePtr = PIECESOFUK.singlesPtr = PIECESOFUK.aboutPtr =
   PIECESOFUK.latestPtr = null;

$(document).ready( function() {
	return;
	$("body").show();
  $.translate(function(){ //when the Google Language API is loaded
		    $.translate().ui('select', 'option').change(function(){ //when selecting another language
      $('.translatable').translate( 'english', $(this).val(), { //translate from english to the selected language
          not: '.notTranslatable', //exclude these elements
          fromOriginal:true //always translate from english (even after the page has been translated)
      });
    }).val('English').appendTo('#Linktranslate'); //insert the dropdown to the page
  });
  $.translate().getBranding("googleBranding", "horizontal" );
	$(".mailme").each(function() {
		$(this.childNodes).wrap("<a href='mailto:cmgroves@gmail.com' target='_blank'></a>");
	});

//  PIECESOFUK.bodyWidth = $("body").width();
//  PIECESOFUK.bodyHeight = $(window).height();

  PIECESOFUK.infoViewPtr = new PIECESOFUK.infoView();

//  new PIECESOFUK.about();
  PIECESOFUK.latestPtr = new PIECESOFUK.latest();

/*
  if ( $("script").eq(2).attr("src") != "Javascript/POUKindex.min.js") {
    alert("Running in test mode: do not update");
  }

*/

  $("#main > ul").tabs().bind('tabsselect', function(event, ui) {
    if (ui.index != 0) {
//		  if (ui.index == 4) $("#calView").height($(window).height() - $("#main").height() - 10);
console.log($(window).height() + " " + $("#main").height() + " " + $("#calControls").css("height") );
		  if (ui.panel.id == "calendar")
			  $("#calView").height( $(window).height() - $("#main").height() - parseInt($("#calControls").css("height"), 10) - 18);
      if ($("#infoViewContainer").dialog('isOpen')) {
//	updated for ui 1.6			$("#infoViewContainer").parent().parent().css("visibility", "hidden");
				$("#infoViewContainer").parent().css("visibility", "hidden");
      }
    } else {
//	updated for ui 1.6		$("#infoViewContainer").parent().parent().css("visibility", "visible");
			$("#infoViewContainer").parent().css("visibility", "visible");
    }
  });


  setTimeout(PIECESOFUK.controller, 1000); // temp modified as not working in jq1.3/jqui1.6
/*
	$("#Linkabout").click( function(e) {
    e.preventDefault();
//    PIECESOFUK.aboutPtr = new PIECESOFUK.about();
    new PIECESOFUK.about();
    return false;
	});

  $(".infoView").click( function(e) {
    e.preventDefault();
    var fn = eval("PIECESOFUK." + $(this).attr("id").slice(4));
    PIECESOFUK.infoViewFn = PIECESOFUK.youTubeFn = new fn();
    return false;
  });
*/

  $(".infoView").click( function(e) {
    e.preventDefault();
    var fn = $(this).attr("id").slice(4);
		if (fn === "singles" && !PIECESOFUK.singlesPtr) {
			PIECESOFUK.singlesPtr = new PIECESOFUK.singles();
		} else
		if (fn === "youTube" && !PIECESOFUK.youTubePtr) {
			PIECESOFUK.youTubePtr = new PIECESOFUK.youTube();
		} else
		if (fn === "about" && !PIECESOFUK.aboutPtr) {
			PIECESOFUK.aboutPtr = new PIECESOFUK.about();
		} else
		if (fn === "latest" && !PIECESOFUK.latestPtr) {
			PIECESOFUK.latestPtr = new PIECESOFUK.latest();
		} else
		if (fn === "songs") {
			$.ajax( {
				type: "GET",
				async: false,
				url: "Javascript/songs.js",
				dataType: "script",
				error: function(XMLHttpRequest, textStatus, errorThrown) {
				  alert("Error: Failed to load songs data: " + textStatus + " " + errorThrown);
			  },
				success: function (data, textStatus) {
   			}
      });
		}

    return false;
  });


});



window.onload = function() {
//  PIECESOFUK.bodyWidth = $("body").width();
//  PIECESOFUK.bodyHeight = $(window).height();

  var castWidth = $("#infoView").width();
  var calendarDetsWidth = $("#calendarDetails").width()
  var jewelsBlogWidth = $("#jewelsBlog").width();
//  $("#calendarContainer").width(PIECESOFUK.bodyWidth - calendarDetsWidth - 30);
  var ie = 0; if ($.browser.msie) ie = 10;
//  $("#POUKBlogContainer").width(PIECESOFUK.bodyWidth - castWidth - 20 - ie);
  $("#POUKBlogContainer").width($("body").width() - castWidth - 20 - ie);
}

PIECESOFUK.addScript = function(theURL) {
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = theURL;
  document.getElementsByTagName('head')[0].appendChild(script);
};

PIECESOFUK.thisWeek = function() {

}

PIECESOFUK.sortDates = function(a, b) {
  var x = a.Date.valueOf();
  var y = b.Date.valueOf();
  return ((x < y) ? 1 : ((x > y) ? -1 : 0));
}
